<template>
  <div class="workingCircle">
    <div class="workingCircle-left">
      <div class="nav-box">
        <div class="search">
          <input type="text" @input="search_project" v-model="search_project_name" placeholder="搜素项目名称"/>
        </div>
        <ul class="nav-list">
          <li :class="type==1?'active':''">
            <div class="title" @click="openProjectClassifyList">项目分类<i :class="is_show_projectClassify?'rotate':''"></i>
            </div>
            <div class="list" v-if="is_show_projectClassify">
              <vuescroll :ops="ops">
                <ul class="ul">
<!--                  <li :class="['ellipsis1',item.is_active?'active':'']" v-for="(item,index) in project_list"-->
<!--                      @click="queryWorkingCircle(item)">{{item.shortName}}-->
<!--                  </li>-->
                  <li :class="['ellipsis1',item.id==workingCircle_id?'active':'']" v-for="(item,index) in project_list"
                      @click="queryWorkingCircle(item)">{{item.shortName}}
                  </li>
                </ul>
              </vuescroll>
            </div>
          </li>
          <li :class="type==2?'active':''">
            <div class="title" @click="aboutMe_workingCircle">与我相关</div>
          </li>
        </ul>
        <div class="add-dynamic" @click="is_show_addDynamic=true">
          <i></i>
          发布动态
        </div>
      </div>
    </div>
    <div class="workingCircle-right">
      <router-view/>
    </div>
    <transition name="fade">
      <div v-if="is_show_addDynamic">
        <addDynamic @close="close_addDynamic" @update="update"></addDynamic>
      </div>
    </transition>
  </div>
</template>

<script>
  import vuescroll from 'vuescroll'
  import addDynamic from '@/components/addDynamic/index'; //消息弹窗

  export default {
    name: "WorkingCircle",
    components: {
      vuescroll, addDynamic
    },
    data() {
      return {
        search_project_name: '',
        timerIndex: '',
        is_show_addDynamic: false,//是否显示发布动态框
        type: '1',//1项目分类 2 与我相关
        is_show_projectClassify: false,//是否显示项目分类列表
        ops: {
          vuescroll: {
            wheelDirectionReverse: false,//true：横向滚动，false：竖向滚动
            wheelScrollDuration: 0,//滚动速度
            mode: 'native',
            sizeStrategy: 'percent',
            detectResize: true
          },
          scrollPanel: {
            scrollingX: false,//启用横屏滚动
            scrollingY: true,//关闭竖向滚动
          },
          rail: {
            background: '#e5ebf1',
            opacity: 1,
            size: '6px',
            borderRadius: '6px',
            gutterOfEnds: '60px',//轨道距 x 和 y 轴两端的距离
            gutterOfSide: '5px'//距离容器的距离
          },
          bar: {
            onlyShowBarOnScroll: false,//是否只在滚动时显示bar
            background: '#cbd5df',
            keepShow: true,
            size: '4px',
            minSize: false
          }
        },//滚动配置
        project_list: [],//项目列表
        workingCircle_id: '',//工作圈的项目id
      }
    },
    created() {
      this.type = this.$route.query.type || 1;
      this.workingCircle_id = this.$route.query.projectId || '';
      this.get_project_list();
    },
    methods: {
      update() {
        this.$router.push({
          path: '/workingCircle/workingCircleProject',
          query: {type: 1, projectId: '', date: new Date().getTime()}
        });

      },
      //搜素项目
      search_project() {
        clearTimeout(this.timerIndex);
        this.timerIndex = setTimeout(() => {
          this.$router.push({
            path: '/workingCircle/workingCircleProject',
            query: {type: 1, projectName: this.search_project_name}
          });
        }, 1000)
      },
      //关闭发布动态
      close_addDynamic() {
        this.is_show_addDynamic = false;
      },
      //展示或者关闭项目分类列表
      openProjectClassifyList() {
        this.is_show_projectClassify = !this.is_show_projectClassify;
      },
      //查询项目列表
      get_project_list() {
        this.$http.post('project/project/list', {
          pageNum: 1,
          pageSize: 200,
          userId: this.$store.state.userInfo.userId,
        }).then(res => {
          if (res.statusCode == 200) {
            let list = res.data.list;
            list.map(function (item) {
              item.is_active = false;
            });
            list.unshift({
              id: '',
              shortName: '全部项目',
              is_active: true,
            });
            this.project_list = list;
          } else {
            this.$message.error(res.statusMsg)
          }
        })
      },
      //查询工作圈
      queryWorkingCircle(data) {
        console.log(data);
        this.type = 1;
        this.project_list.map(function (item, index) {
          item.is_active = false;
        });
        data.is_active = true;
        this.workingCircle_id = data.id;
        this.$router.push({
          path: '/workingCircle/workingCircleProject',
          query: {type: 1, projectId: data.id}
        });
      },
      //与我相关的工作圈
      aboutMe_workingCircle() {
        this.workingCircle_id='id';
        this.type = 2;
        this.is_show_projectClassify = false;
        this.$router.push({
          path: '/workingCircle/workingCircleProject',
          query: {type: 2}
        });
      },
    }
  }
</script>

<style scoped type="text/scss" lang="scss">
  .workingCircle {
    width: 100%;
    height: 100%;
    display: flex;
    position: relative;

    .workingCircle-left {
      width: 280px;
      height: 100%;
      padding: 24px 0 24px 24px;

      .nav-box {
        width: 100%;
        height: 100%;
        background-color: #ffffff;
        border-radius: 6px;

        .search {
          padding-top: 24px;
          padding-bottom: 32px;

          > input {
            display: block;
            width: 208px;
            line-height: 40px;
            height: 40px;
            background-color: #F2F6F9;
            border-radius: 6px;
            margin: 0 auto;
            border: none;
            text-indent: 11px;
            font-size: 14px;
          }
        }

        .nav-list {
          padding: 0 32px;

          > li {
            margin-bottom: 32px;

            .title {
              line-height: 1;
              position: relative;
              font-size: 16px;
              color: #96a2aa;
              cursor: pointer;

              i {
                background-image: url("../../assets/img/bottom_icon.png");
                background-size: 10px 6px;
                background-repeat: no-repeat;
                background-position: center;
                position: absolute;
                width: 10px;
                height: 6px;
                right: 0;
                top: 5px;
                transition: 0.5s all;
              }
            }

            .list {
              margin-top: 32px;

              .ul {
                padding-left: 16px;
                max-height: 252px;

                > li {
                  padding-bottom: 30px;
                  font-size: 14px;
                  cursor: pointer;
                  color: #96A2AA;
                }

                > li:last-child {
                  padding-bottom: 0;
                }

                > li.active {
                  color: #0A52E4;
                }
              }
            }

            i.rotate {
              transform: rotate(180deg);
            }
          }

          > li.active {
            .title {
              color: #454a55;
              font-weight: bold;
            }

          }
        }
      }

      .add-dynamic {
        position: absolute;
        left: 91px;
        bottom: 48px;
        width: 122px;
        height: 40px;
        line-height: 40px;
        border-radius: 6px;
        background-color: #FF8F2B;
        text-indent: 47px;
        color: #ffffff;
        font-size: 14px;
        cursor: pointer;

        i {
          position: absolute;
          background-image: url("../../assets/img/ic_add-project.png");
          background-repeat: no-repeat;
          background-position: center;
          background-size: cover;
          width: 14px;
          height: 14px;
          left: 28px;
          top: 13px;
        }
      }
    }


    .workingCircle-right {
      width: calc(100% - 280px);
      padding: 24px 24px 0 24px;
    }
  }
</style>
